package D4;

public class Java05 {
    public static void main(String[] args) {
        //目标：掌握正则表达式的书写规则
        //1、字符类(只能匹配单个字符)
        System.out.println("a".matches("[abc]"));//[abc]只能匹配abc
        System.out.println("e".matches("[abcd]"));//false

        System.out.println("d".matches("[^abc]"));//不能是abc
        System.out.println("a".matches("[^abc]"));

        System.out.println("b".matches("[a-zA-Z]"));//只能是a-zA-Z之间的字符
        System.out.println("2".matches("[a-zA-Z]"));

        System.out.println("k".matches("[a-z&&[^bc]]"));//a-z除了bc
        System.out.println("b".matches("[a-z&&[^bc]]"));

        System.out.println("ab".matches("[a-zA-Z0-9]"));//false，注意：以上带【】的规则都只能匹配单个字符

        //2、预定义字符（只能匹配单个字符）
        System.out.println("徐".matches("."));// 可以匹配任意字符
        System.out.println("a徐".matches("."));//可以匹配任意字符
        //转义
        System.out.println("\"");
        // \n \t
        System.out.println("3".matches("\\d"));// \d的意思：0-9
        System.out.println("a".matches("\\d"));

        System.out.println(" ".matches("\\s"));//表示一个空白字符
        System.out.println("a".matches("\s"));

        System.out.println("a".matches("\\S"));
        System.out.println(" ".matches("\\S"));

        System.out.println("a".matches("\\w")); //[a-zA-Z_0-9]
        System.out.println("_".matches("\\w"));
        System.out.println("徐".matches("\\w"));

        System.out.println("徐".matches("\\W"));//不能是a-zA-Z_0-9
        System.out.println("a".matches("\\W"));

        System.out.println("2223324242".matches("\\d"));//注意：以上预定义字符都只能匹配单个字符

    }
}
